/**
 * Created by Brant on 2016/12/28.
 */
module.exports = function ($scope,$state,workBarNoWorkService,$cookies,$rootScope,iScrollService, httpservice) {
  $rootScope.showCaseDiv = false;

  $rootScope.loadingShow = false;
    $scope.iScrollState = iScrollService.state;

  //todo 监听广播，刷新列表 仅刷新备操作的task的列表
  $scope.$on('refreshWorkbarNoWork', function (event, data) {
    // $scope.getWorkbarList();
    $scope.detailAll = data.detailAll;

    if(data.parentsIndex!=null){
      $scope.AJBList[data.parentsIndex].myTasks[data.parentIndex].tasks.splice(data.index,1,$scope.detailAll);

    }else{
      $scope.AJBList[data.parentIndex].myTasks.splice(data.index,1,$scope.detailAll)

    }

  });
  // 详情页点击完成checkbox后，需刷新工作台内的任务里列表，为了减轻后台压力，广播调用clickCheakBoxOverTask或者clickCheckBoxOverEvidenceTask
  $scope.$on('refreshTashStatus', function (event, data) {
    if (data.task.taskType == 1) {
      $scope.clickCheakBoxOverTask(data.task,data.myTasks,data.index,null,data.parentIndex);
    } else if (data.task.taskType == 2){
      $scope.clickCheckBoxOverEvidenceTask(data.task,data.myTasks,data.index,null);
    }
  });
  // 详情页点击取消checkbox后，刷新工作台内的任务里列表
  $scope.$on('refreshUnfinishTashStatus', function (event, data) {
      $scope.clickUnCheckBoxOverTask();
  });
  $rootScope.typeIf=1;


  //判断移动位置
  function moveIndex(evt) {
    var originalEvent=evt.originalEvent.target;
    var panelId = originalEvent.attributes['id'].value;
    var index = originalEvent.attributes['index'].value;
    var caseIndexAttr = originalEvent.attributes['case-index'];
    var list = $scope.AJBList[index].myTasks;
    if(caseIndexAttr) {
      var caseIndex = caseIndexAttr.value;
      //案件任务
      if($scope.AJBList[index].myTasks[caseIndex].tasks.length>1){
        list = $scope.AJBList[index].myTasks[caseIndex].tasks;
      }else{
        list = $scope.AJBList[index].myTasks.splice(caseIndex,1);
      }

    }
    return {
      'list':list,
      'panelId':panelId
    };

  }
  // $(function() {
    $scope.panelConf = {
      animation: 350,
      forceFallback:true,
      disabled: false,
      group: {
        name:'task',
        put:true,
        pull:'clone'
      },
      handle: ".my-handle",
      onChoose: function (/**Event*/evt) {

        evt.oldIndex;  // element index within parent
      },
      onStart: function (/**Event*/evt) {
        evt.oldIndex;  // element index within parent
      },
      onMove: function (/**Event*/evt, /**Event*/originalEvent) {

      },
      onAdd: function (evt) {
        var list = moveIndex(evt);
        var startArr = [];
        if(list.list.length){
          for (var i = 0; i < list.list.length; i++) {
            var taskObj = {
              workBenchPanelId: list.panelId,
              taskId: list.list[i].task.id,
              sequence: i+1,
              taskType: list.list[i].taskType
            };
            startArr.push(taskObj);
          }
        }


        $scope.returnlistid(startArr);
      },
      // Changed sorting within list
      onUpdate: function (/**Event*/evt) {
        var list = moveIndex(evt);
        var startArr = [];
        if(list.list.length){
          for (var i = 0; i < list.list.length; i++) {
            var taskObj = {
              workBenchPanelId: list.panelId,
              taskId: list.list[i].task.id,
              sequence: i+1,
              taskType: list.list[i].taskType
            };
            startArr.push(taskObj);
          }
        }

        $scope.returnlistid(startArr);
      },

      // Element is removed from the list into another list
      onRemove: function (/**Event*/evt) {
        var list = moveIndex(evt).list;
        list.splice(evt.oldIndex, 1);
      },

      // Called when creating a clone of element
      onClone: function (/**Event*/evt) {
        angular.element('.d-closeSiblings').css({"display":"none",'right':'-700px'});

       /* var origEl = evt.item;
        var cloneEl = evt.clone;*/
      }
    };

    //点击回到原来的案件下
    $scope.backToCase = function (otherLi,$event) {
      var startArr = [];
      var params = {
        workBenchPanelId: 1,
        taskId: otherLi.task.id,
        sequence: otherLi.task.sequence,
        taskType: otherLi.taskType,
        caseStageId: otherLi.task.casestageid,
      };
      startArr.push(params);
      workBarNoWorkService.getsortsortable(startArr).then(function (data) {
        if (data.code == 1) {
          //刷新列表
          $scope.getWorkbarList();
        }
      });
      $event.stopPropagation();
    };

    //排序完成请求网络
    $scope.returnlistid = function (startArr,callback) {
      /* taskId	int     	任务ID
       workBenchPanelId	Int	工作台任务面板ID*/
      $rootScope.loadingShow = true;
      $rootScope.fadeShow = true;
      workBarNoWorkService.getsortsortable(startArr).then(function (data) {
        $rootScope.loadingShow = false;
        $rootScope.fadeShow = false;
        if (data.code == 1) {
          //刷新列表
          // $scope.getWorkbarList();
        }else{
        }
      }, function (response) {
        $rootScope.loadingShow = false;
        $rootScope.fadeShow = false;
        console.error('updatemessage error', response.status, response.statusText);
      });
    }

  // });


    $scope.isUpdated = $cookies.get('cookieIsUpdated');
    //获取点击的案件的id
    var caseId = $cookies.get('caseAppId');
    //去用户的名字
    $scope.userPortraitName=$cookies.get('userPortraitName');

    /*登录用户ID*/
    var userId = kbt.decrypt($cookies.get('cookieUserId'));
    $scope.loginId = kbt.decrypt($cookies.get('cookieUserId'));

    //案件板的列表
    $scope.AJBList = [];
    $scope.ajrwList = '';
    $scope.xzjzList = '';


    //现在就做的添加任务
    $scope.MSG = '';
    $scope.MSG3 = '';

    //案件任务里的阶段
    $scope.caseAJRWJD = '';
    $scope.ajrwInput = 'xxx';//添加案件任务或者证据的输入框




    //添加任务面板上传的累加字段
    $scope.squence = 2;
    $scope.addInputName = '';//添加按键板的名字


    //案件列表
    $scope.chooseTaskList = '';
    $scope.chooseTaskList3 = '';

    //案件阶段列表
    $scope.chooseStageList = '';
    $scope.chooseStageList3 = '';
    //已完成的任务
    $scope.overTaskList = [];

    //新建案件版--->添加任务
    $scope.ncanme = '';//记录案件名称
    $scope.nsname = '';//记录案件阶段



    //详情
    //证据详情
    $scope.detailData = '';
    $scope.detailFJ = '';
    $scope.detailUser = '';

    $scope.ETypeList= '';
    //证据评论
    $scope.zcommentInput = '';

    //给taskId赋值
    $scope.addLSTaskId = '';
    //给证据的ID赋值
    $scope.evidenceID = '';

    //进程
    // $scope.detailList = '';
    $scope.plList = '';
    $scope.executors = '';
    $scope.fileList = '';
    $scope.logList = '';

    $scope.detailTaskId = '';
    $scope.detailJd = '';

    //详情里的阶段
    $scope.detailJd = '';
    //律师的列表
    $scope.lawyersList = '';

    //详情评论
    $scope.commentInput = '';
    $scope.caseId = '';

    //详情界面->任务描述的添加的字
    $scope.desInputText = '';

    //收索工作台第一个里边的案件
    $scope.searchCaseBarCase = '';
    $scope.searchCaseBarCase1 = '';


    //火狐冲突,获取焦点
    $scope.getFoucs = function () {
        $("#search").focus();
        $(document).getElementsByClassName('getFirFous').focus();
    };
    $scope.getFirFousB=function(event){
      var e=event.target;
      if($(e).val()==''){
        $(e).addClass('getFirFousBorder');

      }else{
        $(e).removeClass('getFirFousBorder')
      }
    }
    $scope.getFirFous = function () {
        $(".getFirFous").focus();
    }

    $scope.ajrwFrieFocus = function () {
        $('.ajrwFrieFocus').focus();
    }

    $scope.getFirFousTextarea = function () {
        $('.xzjzSe').focus();
    }


    //点击收索按钮收索case
    $scope.searchCaseBarCaseClick = function (text) {
        $scope.searchCaseBarCase = text;
    };


    //这是个问题


  $(document).click(function(e){
    $scope.updateBoxTogger=true;
    if($scope.updateBoxTogger) {
      $('.updateBox').css('display', 'none');
    }
  });
$scope.updateBoxTogger=false;
    //出现修改任务组的盒子
    $scope.showUpdateTaskBox = function ($event) {
      $event.stopPropagation();
        var $event = $event.target;
        var e = $($event);
       $('.updateBox').css('display', 'none');
        $(e).siblings('.updateBox').css('display','block');

    };
    //


    //移除box
    $scope.removeBox = function ($event) {
        $event.stopPropagation();
        var $event = $event.target;
        var e = $($event);

        $(e).parents('.updateBox').css('display','none');
    };

    var ee;

    /**
     * 编辑新增案板的名字
     * @param $event
     */
    $scope.updateName = function ($event, panel) {
        var $event = $event.target;
        ee = $($event);
        $(ee).parents('.updateBox').css('display', 'none');
        $(ee).parents('.updateBox').siblings('.w_manageBtn').css('display', 'none');
        $(ee).parents('.updateBox').siblings('p').css('display', 'none');
        $(ee).parents('.updateBox').siblings('.zqUpdateName').css('display', 'block');
        $('#editModalpanel').modal('hide');
        //文字带入
        panel.updateNameText = panel.panelName;
    };


    /**
     * 点击编辑案板确认
     * @param $event
     */
    $scope.updateNameConfirm = function () {
        $(ee).parents('.updateBox').css('display', 'none');
        $(ee).parents('.updateBox').siblings('p').css('display', 'none');
        $(ee).parents('.updateBox').siblings('.zqUpdateName').css('display', 'block');
        $('#editModalpanel').modal('hide');
    };



    /**
     * 点击图片修改名字
     * @param $event
     * @param text
     * @param panelId
     */
    $scope.updateNameYes = function ($event,other) {

        var $event = $event.target;
        var e = $($event);

        workBarNoWorkService.updatePanelName(other.panelId, other.updateNameText).then(function (data) {
            if(data.code == 1){
                $(e).parents('.zqUpdateName').css('display','none');
                $(e).parents('.zqUpdateName').siblings('p').css('display','block');
                $(e).parents('.zqUpdateName').siblings('.w_manageBtn').css('display', 'block');
                other.panelName =other.updateNameText;
                // other.updateNameText = "";
                //刷新列表
                //$scope.getWorkbarList();
            }
        });
    };
  $scope.updateNameNo=function($event){
    var $event = $event.target;
    var e = $($event);
    $(e).parents('.zqUpdateName').css('display','none');
    $(e).parents('.zqUpdateName').siblings('.w_manageBtn').css('display', 'block');
    $(e).parents('.zqUpdateName').siblings('p').css('display','block');
  }

    /**
     * 点击删除案板
     * @param $event
     * @param panelId
     */
    $scope.deleteEGroup = function ($event,panelId, $index){
        /*将案板ID放入模态框隐藏input中*/
        var $event = $event.target;
        ee = $($event);
        $(ee).parents('.updateBox').css('display', 'none');
        $('#hiddenval').val($index);

    };

    /**
     * 点击确定删除案板
     * @param $event
     */
    $scope.deletePanelConfirm = function ($event){

        var $event = $event.target;
        var e = $($event);
        /*获取模态框中隐藏的案板ID*/
        // var panelId = $('#hiddenval').val();
        var index = $('#hiddenval').val();
        var panel = $scope.AJBList[index];
        workBarNoWorkService.deletePanel(panel.panelId).then(function (data) {
            if (data.code == 1) {
                $(e).parents('.updateBox').css('display', 'none');
                // $scope.getWorkbarList();
                $('#deleteModalpanel').modal('hide');
                $(".zqNoTaskBigBody").width($(".zqNoTaskBigBody").width()-300);
                $scope.AJBList.splice(index, 1);
              var len = 410 + parseInt($scope.AJBList.length) * 340;
              //如果获取的任务数量太少，则给面板一个固定宽度
              if (len < 1320) {
                $(".zqNoTaskbody").width(1320);
              } else {
                $(".zqNoTaskbody").width(len);
                $(".wrap").width(len);

              }
                //刷新界面
                // $scope.getWorkbarList();
            }
        });

    };

    $scope.deleteButHaveTaskPanelConfirm = function ($event) {
        $('#deleteButHaveTaskModalpanel').modal('hide');
    }


    /**
     * 点击案件任务的复选框,点完,变成完成事件,刷新列表
     * @param taskId
     */
    $scope.clickCheakBoxOverTask = function (t,tasks,index,$event,parentIndex) {
      $rootScope.loadingShow = true;
      $rootScope.fadeShow = true;

      workBarNoWorkService.updateTask(t.task.id,"1",t.title,$scope.loginId,t.task.caseid,$scope.userPortraitName).then(function (data) {
        $rootScope.loadingShow = false;
        $rootScope.fadeShow = false;
        if(data.code == 1){
          if(tasks){
            tasks.splice(index,1);
          }else{
            $scope.AJBList[parentIndex].myTasks.splice(index,1);
          }
          $scope.overTaskList.noMore=$scope.overTaskList.noMore?!$scope.overTaskList.noMore:$scope.overTaskList.noMore;
          /*var TaskList={
            'title':t.task.title,
            'taskType':t.taskType,
            'deadline':t.deadline,
            'executor':t.taskExecutors
          }*/
          $scope.overTaskList.unshift(t);//TaskList

        }
      });
      if($event != null)
        $event.stopPropagation();
    };

    /**
     * 取消案件任务详情的复选框,变成将完成的任务会退至未完成列表
     * @param taskId
     */
    $scope.clickUnCheckBoxOverTask = function (t,tasks) {
      // for(var index = 0; index < $scope.overTaskList.size(); index++ ) {
      //   if(t.id == tasks[index].id )
      //     $scope.overTaskList.splice(index,1);
      // }
      // tasks.unshift(t);
      //刷新大的列表
      $scope.getWorkbarList();
    };

    //完成证据任务
    $scope.clickCheckBoxOverEvidenceTask = function (t, tasks, index, $event) {
      $rootScope.loadingShow = true;
      $rootScope.fadeShow = true;

      workBarNoWorkService.updateEDDate(t.id).then(function (data) {
        $rootScope.loadingShow = false;
        $rootScope.fadeShow = false;
        if(data.code == 1){
          tasks.splice(index,1);
          $scope.overTaskList.unshift(t);
        }
      });
      if($event != null)
        $event.stopPropagation();
    };

    //点击已完成的,把已完成的放回来
    $scope.clickCheakBoxUnOver = function (taskId,title,caseid,index) {
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        workBarNoWorkService.updateTask(taskId,"0",title,$scope.loginId,caseid,$scope.userPortraitName).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if(data.code == 1){
              //刷新已完成列表
              $scope.showOverTask();
              //$scope.overTaskList.splice(index,1);
              //刷新大的列表
              $scope.getWorkbarList();
            }
        })
    };


    $scope.init = function(){
        /*=====关闭右侧弹出框====*/
        /*//证据面板弹框
        $(".closeDetail").click(function () {
            $(this).parents(".rightComeToZJ").animate({
                "right": "-700"
            }, 300);

        });
        $("#sortable2").click(function () {
            $(".rightComeToZJ").animate({
                "right": "0"
            }, 300);
        });
        //案件进程弹框
        $(".closeDetail").click(function () {
            $(this).parents(".rightComeTo").animate({
                "right": "-700"
            }, 300);

        });
        $("#sortable1").click(function () {
            $(".rightComeTo").animate({
                "right": "0"
            }, 300);
        });*/
    };
    $scope.init();/*鍒濆鍖栧嚱鏁�*/
    /*添加案件*/
    $scope.toUserInfo = function(){
      /*跳转到新建案件*/
      $state.go('caseBar', {from: 'workbar'});
    };
    /*鍩烘湰淇℃伅鎺ュ彛*/
    $scope.selectInfon = function(){
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        workBarNoWorkService.selectInfon().then(function (data) {
            if(data.code == 1){

            }
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
        }, function () {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
        });
    };





//新建按键板------------------------------------------------
    //点击现在就做的添加按钮
    var $event ;
    $scope.showAddNowWork3 = function ($event,other){
      var $event = $event.target;
      $('.zqAddDiv').css('display',"block");
      $scope.chooseStageList3='';
      $scope.nsname='';
      other.note='';
      workBarNoWorkService.chooseTask(userId).then(function (data) {
        if(data.code == 1){
            $scope.chooseTaskList3 = data.data;

        }
      });
      $('.zqNewGreat').hide();
      var e = $($event);
      var oldHeight = $(window).height()-305 + 'px';
      var newHeight = $(window).height()-450 + 'px';
      var oDiv = $(e).parents('.zqAddDiv').siblings('.zqNewGreat');//.children('.zqNewGreat')
      oDiv.css('display','block');
      $(".g-wrapper").css("max-height",oldHeight);
      $(e).parents('.zqAddDiv').css('display','none');
      $(e).parents('.zqtow').children('.g-wrapper').css("max-height",newHeight);
    };

    //选择案件名称获取案件阶段列表
    $scope.chooseCase3 = function (model) {
      if (model == null) {
        return;
      }
        //$(".xzjzSe").click();

        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;

        if($scope.chooseTaskList3.length > 0){
            $scope.ncname = model;
            workBarNoWorkService.chooseJD(model.id).then(function (data) {
                $rootScope.loadingShow = false;
                $rootScope.fadeShow = false;
                $scope.chooseStageList3 = data.data;
                $scope.nsname=data.data.length?data.data[0].id:'';
            });
        }
    }

    //记录案件阶段
    /*$scope.chooseStage3 = function (model) {
        $scope.nsname = model;
    };*/

    $scope.saveTask3 = function ($event,panel,textAText){
        var $event = $event.target;
        var e = $($event);
        if(textAText.length > 0){
            $scope.MSG3 = textAText;
            if($scope.ncname){
              workBarNoWorkService.addTask($scope.MSG3,$scope.ncname.id,$scope.nsname,'',userId,userId,panel.panelId,$scope.userPortraitName).then(function (data) {
                if(data.code == 1){
                  var oldHeight = $(window).height()-305 + 'px';
                  $(".g-wrapper").css("max-height",oldHeight);
                  $(e).parents('.zqNewGreat').css('display','none');
                  $(e).parents('.zqNewGreat').siblings('.zqAddDiv').css('display','block');
                  //将添加的任务放入对应的案件板中
                  data.data.taskType = 1;//默认普通案件任务
                  data.data.attr1 = $scope.ncname.casename;//貌似是记录案件名字 会报错 先注释了
                  panel.myTasks.push(data.data);
                  //清空数据
                  panel.note = '';
                  $scope.chooseTaskList3 = '';
                  $scope.chooseStageList3 = '';
                }
              })

            }else{
              bootbox.dialog({
                message: "请先创建案件！",
                title: "提示信息",
                className:'d-promptBox',
                buttons: {
                  OK: {
                    label: "确定",
                    className: "d-btn-confirm5",
                    callback: function () {

                    }
                  }
                }
              });
            }
        }
    }

//新建按键板------------------------------------------------

    //取消现在就做的添加按钮
    $scope.dataCancelClick = function ($event,other) {
      var $event = $event.target;
      var e = $($event);
      var oldHeight = $(window).height()-305 + 'px';
      other.note='';
      $scope.chooseStageList3='';
      $scope.nsname='';
      $(".g-wrapper").css("max-height",oldHeight);
      $(e).parents('.zqNewGreat').css('display','none');
      $(e).parents('.zqNewGreat').siblings('.zqAddDiv').css('display','block');
    };

    //点击取消按钮
    $('#nowDoCancel').click(function(){
        $('.zqNoTasknowBody .zqNewGreat').css('display','none');
    });


    //出现案件任务添加盒子
    $scope.zqBox1addClick = function ($event,caseId) {
      $('.zqNewGreat').hide();
      $('.w_addTask').hide();
      $('.zqAddDiv').show();
      $('getFirFous').removeClass('getFirFousBorder');
        var $eve = $event.target;
        var e = $($eve);
        $(e).parents('.g-lineOuter').siblings('.zqNewGreat').css('display','block');
        $(e).siblings('.w_addTask').css('display','block');

        workBarNoWorkService.chooseJD(caseId).then(function (data) {
            if(data.code == 1){
                $scope.caseAJRWJD = data.data;
            }
        });
        $event.stopPropagation();
    };
    //点击确定,提交
    $scope.addTaskOrEvi = function ($event,task) {
        var $event = $event.target;
        var e = $($event);
        //判空
        if(task.ajrwInput!=''){
            //找到他的ID
            var a = $(e).parent('div').prev("div").find('option:selected').val();
            $rootScope.loadingShow = true;
            $rootScope.fadeShow = true;

            workBarNoWorkService.addTask(task.ajrwInput,task.caseId,a,"",userId,userId,"1",$scope.userPortraitName).then(function (data) {
                $rootScope.loadingShow = false;
                $rootScope.fadeShow = false;
                if(data.code == 1){
                    data.data.taskType = 1;
                    task.tasks.push(data.data);
                    task.ajrwInput = '';
                    $('.w_addTask').hide();
                }
            });
        }
    };

    //点击取消案件任务添加盒子
    $scope.box1cannelClick = function ($event) {
        var $event = $event.target;
        var e = $($event);
        $(e).parents('.w_addTask').css('display','none');
    }

    //案件任务下拉列表
    $scope.zqlistBtnClick = function ($event, other) {
      if (other.showtask) {
        other.showtask = false;
      } else {
        other.showtask = true;
      }

    };



    $('.zqAddDiv').click(function () {
        if ($('.nowBody .zqNewGreat').css('display')=='block') {
            $('.nowBody .zqNewGreat').css('display','none');
        }else  {
            $('.nowBody .zqNewGreat').css('display','block');
        }

    });

    //点击取消
    $('.cannel').click (function (){
        $('.nowBody .zqNewGreat').css('display','none');
    });
    //点击已完成任务
    $('.zqspanr').click(function (){

        if ($('.zqOverJob').css('display')=='block') {
            $('.zqOverJob').css('display','none');
        }else  {
            $('.zqOverJob').css('display','block');
        }
    });

    //点击现在就做的checkBox
    $('.checkBoxClick').click(function (){
        if ($(this).is(":checked")) {
            $(this).siblings('p').css('text-decoration','line-through');
        } else {
            $(this).siblings('p').css('text-decoration','none');
        }

    });

    //点击新增(与现在就做并列)
    $('#addThirdDiv').click(function () {
        $('.ThirdDiv').css('display','block');
    });

    //第三个点击取消
    $('#cancel').click (function (){
        $('.ThirdDiv').css('display','none');
    });



    //进来获取任务列表
    $scope.getWorkbarList = function () {
        workBarNoWorkService.getWorkBarList(userId).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;

            if(data.code == 1){
                $scope.AJBList = data.data;
                //根据案板数量对应增加布局宽度
                var len = 410 + parseInt($scope.AJBList.length) * 340;
                //如果获取的任务数量太少，则给面板一个固定宽度
                if (len < 1320) {
                    $(".zqNoTaskbody").width(1320);
                } else {
                    $(".zqNoTaskbody").width(len);
                    $(".wrap").width(len);

                }


                for(var i = 0;i < $scope.AJBList.length;i++){
                    $scope.squence = $scope.AJBList[i].sequence;
                }

            }
        });
    };
  $scope.getWorkbarList();


    /**
     * 添加任务面板
     * @param text
     */
    $scope.addWorkBarPannel = function (text) {
        if(text != ''){
          $scope.squence = $scope.squence + 1;

          $rootScope.loadingShow = true;
          $rootScope.fadeShow = true;

          workBarNoWorkService.addWorkBarPanel(userId,text,$scope.squence).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if(data.code == 1){
              $scope.addInputName = '';
              $('.ThirdDiv').css('display','none');
              $scope.AJBList.push(data.data);
              //刷新任务面板
              //$scope.getWorkbarList();

              //根据案板数量对应增加布局宽度
              var len = 410 + parseInt($scope.AJBList.length) * 336;
              //如果获取的任务数量太少，则给面板一个固定宽度
              if (len < 1320) {
                $(".zqNoTaskbody").width(1320);
              } else {
                $(".zqNoTaskbody").width(len);
                $(".wrap").width(len);
              }
            }
          });
        }
    };

    /**
     * 取消删除案板
     */
    $scope.deleteCancel = function () {
        /*隐藏确认弹出框*/
        $("#deleteModal").modal('hide');
    };

    //获取用户完成的任务列表
    $scope.showOverTask = function (next) {
        if (next) {
          $scope.overtaskPageNum++;
        } else {
          $scope.overtaskPageNum = 1;
          $scope.overTaskList = [];
        }
        var params = {
          "status": '1',
          "pageNum": $scope.overtaskPageNum
        };
        workBarNoWorkService.getUserTaskList(params).then(function (data) {
            if(data.code == 1){
              $scope.overTaskList = $scope.overTaskList.concat(data.data);
              // if(!data.data.length && data.data.length<6){
              //   $scope.overTaskList.noMore = true;
              // }else{
              //   $scope.overTaskList.noMore = false;
              // }
              if(data.totalPage <= $scope.overtaskPageNum){
                $scope.overTaskList.noMore = true;
              }else{
                $scope.overTaskList.noMore = false;
              }
              /*data.data.attr1 = $scope.ncname.casename;*///貌似是记录案件名字 会报错 先注释了
            }
        })
    };

    //P标签点击添加任务描述
    $('.jaddTaskPClick').click(function () {
        $('#shuxieqisu').addClass('hide');
        $('.jtextareaAndSaveBox').removeClass('hide');

        $('#jqisuzhunbei1').removeClass('hide');
        $('#jqisuzhunbei').addClass('hide');

    });
    //点击名字,出现编辑框
    $('.jtitleName').click(function () {
        $('#shuxieqisu').addClass('hide');
        $('.jtextareaAndSaveBox').removeClass('hide');

        $('#jqisuzhunbei1').removeClass('hide');
        $('#jqisuzhunbei').addClass('hide');

    });
    //点击取消,显示P标签
    $('.jaddTaskCancelBtn').click(function () {
        $('.jtextareaAndSaveBox').addClass('hide');
        $('#shuxieqisu').removeClass('hide');
        $('#jqisuzhunbei').removeClass('hide');
        $('#jqisuzhunbei1').addClass('hide');
    });


    //添加任务人
    /*=====添加律师成员=======*/
    //点击出现BOX
    //$('.showAddPeopleBox').click(function () {
    //    $(".LawyerAddBody").toggle();
    //
    //});
    $(".LawyerList li").on("click",function(){
        var i = $(this).index();
        $(this).addClass("active").siblings().removeClass("active");
        $(this).parent().siblings(".LawyerDiv").find(".Lawyerbox").addClass("hide");
        $(this).parent().siblings(".LawyerDiv").find(".Lawyerbox").eq(i).removeClass("hide");
    });
    $(".LawyerAddBody .Add-close").on("click",function(){
        $(".LawyerAddBody").addClass('hide');
    });

    //底部的评论之类的
    $('.pl').click(function () {
        $(this).addClass('clickActive');
        $(this).siblings().removeClass('clickActive');

        $('.plDiv').css('display','block');
        $('.rwrzDiv').css('display','none');

        $('#zhalf2').css('display','block');
    });
    $('.rwrz').click(function () {
        $(this).addClass('clickActive');
        $(this).siblings().removeClass('clickActive');

        $('.rwrzDiv').css('display','block');
        $('.plDiv').css('display','none');

        $('#zhalf2').css('display','block');
    });

//获取证据类型列表,搜索前边的
    $scope.getETypeList = function () {
        workBarNoWorkService.getETypeList().then(function (data) {
            if (data.code == 1) {
                $scope.ETypeList = data.data;
            }
        })
    };
    $scope.getETypeList();


    //点击屏幕让详情消失
    $('.zqNoTaskBigBody').click(function () {

        if($('.rightComeToZJ').css('right')=='0px'){

            $('.rightComeToZJ').animate({
                "right": "-700"
            }, 300);
        }
        if($('.rightComeTo').css('right')=='0px'){

            $('.rightComeTo').animate({
                "right": "-700"
            }, 300);
        }
        if ($('.zqOverJob').css('display')=='block') {
          $('.zqOverJob').css('display','none');
        }
    })
  document.body.onselectstart = function(){ return false;}

};
